<template>
	<view>
		<!-- 状态栏占位符h5 -->
		<view class="status_bar"></view>

		<!-- #ifdef MP -->
		<!-- 微信小程序胶囊区域占位 -->
		<view class="z-16" :style="{'height':navibarHeight+'px'}" />
		<!-- #endif -->



		<!-- 顶部导航栏开始 -->
		<view class="fixed z-16" style="width: 100%;">
			<view class="third-bg-color flex h-100r">
				<view class="flex-1"></view>
				<view class="flex-4 flex justify-around items-center">
					<view class="text-33r font-600 " :style="{color: curTabIndex==0 ? fontColor : ''}"
						@click="clikeTabNav(0)">关注</view>
					<view class="text-33r font-600" :style="{color: curTabIndex==1 ? fontColor : ''}"
						@click="clikeTabNav(1)">发现</view>
					<view class="text-33r font-600" :style="{color: curTabIndex==2 ? fontColor : ''}"
						@click="clikeTabNav(2)">附近</view>
				</view>
				<view @click="goSearch" class="flex flex-1 flex-center">
					<text class="text-deep text-50r font-600 iconfont icon-sousuo"></text>
				</view>
			</view>
		</view>
		<!-- 占位 -->
		<view class="h-100r"></view>
		<!-- 顶部导航栏结束 -->

		<!-- 主体内容部分开始 -->
		<view class="">
			<swiper @transition="stopPull" class="swiper"  style="height: calc(100vh - 160rpx);" :current="curTabIndex" @change="swiperChange">
				<swiper-item>
					<scroll-view :refresher-enabled="enableRefresh" @refresherrefresh="indexRefresh" :refresher-triggered="trigger"
						scroll-y="true" style="height: 100%; background-color: #E5E5E5;">
						<view class="">
							<scroll-view class="whitespace-nowrap p-20r"  scroll-x="true" style="width: 100%;background-color: #fff;">
								<view v-for="(idx) in [0,1,2,3,4,5,6]" class="inline-block w-150r">
									<view  class="flex flex-col flex-center ">
										<view class="h-120r w-120r rounded-60r main-bg-color flex flex-center">
											<image class="w-100r h-100r  rounded-50r "  src="../../static/logo.png" mode="aspectFill"></image>
										</view>
										<text>nicheng</text>
									</view>
								</view>

								
							</scroll-view>
						</view>
						<view v-for="(item,index) in data.dynamics" :key="index" class="p-10r mb-20r"
							style="border-bottom: 2rpx solid #E5E5E5 ; background-color: #fff;">
							<!-- 动态顶部 -->
							<view
								class="pb-5r flex items-center border-solid border-top-0 border-right-0 border-left-0 border-bottom-2r"
								:style="{'border-color':this.theme.thirdColor}">
								<!-- 头像 -->
								<view @click="goHomePage(item, index)" class="flex-1">
									<image :src="item.publisher.avatar" class="w-100r h-100r rounded-50r mr-15r ml-15r"
										style="background-color: aqua;" mode="aspectFill"></image>
								</view>
								<view class="flex flex-col flex-3">
									<text class="text-36r font-600">{{item.publisher.nickname}}</text>
									<text class="text-20r">{{vk.pubfn.dateDiff(item._add_time)}}</text>
								</view>
								<!-- 头像结束 -->

								<!-- 浏览 转发量 -->
								<view class="flex flex-1 items-center justify-around">
									<view class="flex items-center">
										<text class="mr-10r text-40r iconfont icon-fire" style="color: red;"></text>
										<text class="text-main">{{item.view_count}}</text>
									</view>
									<!-- 									<view class="flex items-center">
										<text class="text-50r iconfont icon-fenxiang1"></text>
										<text>10000</text>
									</view> -->
								</view>
								<!-- 浏览 转发量 结束 -->
							</view>
							<!-- 动态顶部 结束-->

							<!-- 内容部分 -->
							<view @click="itemClick(item,index)" class="pl-10r pr-10r">
								<text class="lines-2 truncate pt-10r mb-10r">{{item.content}}</text>
								<view v-if="item.dynamic_banner_imgs.length > 1" class="flex justify-around">
									<image class="w-360r h-360r rounded-15r mr-5r" :src="item.dynamic_banner_imgs[0]"
										mode="aspectFill">
									</image>
									<image class="w-360r h-360r rounded-15r ml-5r" :src="item.dynamic_banner_imgs[1]"
										mode="aspectFill">
									</image>
								</view>
								<view v-else class="flex justify-around">
									<image class="w-700r h-700r rounded-15r mr-5r" :src="item.dynamic_banner_imgs[0]"
										mode="aspectFill">
									</image>
								</view>
							</view>
							<!-- 内容部分 结束 -->

							<!-- 包含设计作品 -->
							<view v-if="item.hasWork" class="mt-20r flex items-center pl-5r pr-5r h-80r"
								style="border-top: 2rpx solid #E5E5E5 ;">
								<image class="w-60r h-60r" src="../../static/logo.png" mode=""></image>
								<text class="text-26r flex-1 ml-15r">唯衣夏日T恤</text>
								<view class="text-light flex items-center text-30r">
									<text>相关设计</text>
									<text class="iconfont icon-youjiantou"></text>
								</view>
							</view>
							<!-- 包含设计 结束 -->
						</view>
					</scroll-view>
				</swiper-item>
				<swiper-item >
					<!-- 动态 开始 -->
					<scroll-view refresher-enabled @refresherrefresh="indexRefresh" :refresher-triggered="trigger"
						scroll-y="true" style="height: 100%; background-color: #E5E5E5;">		
						<view v-for="(item,index) in data.dynamics" :key="index" class="p-10r mb-20r"
							style="border-bottom: 2rpx solid #E5E5E5 ; background-color: #fff;">
							<!-- 动态顶部 -->
							<view
								class="pb-5r flex items-center border-solid border-top-0 border-right-0 border-left-0 border-bottom-2r"
								:style="{'border-color':this.theme.thirdColor}">
								<!-- 头像 -->
								<view @click="goHomePage(item, index)" class="flex-1">
									<image :src="item.publisher.avatar" class="w-100r h-100r rounded-50r mr-15r ml-15r"
										style="background-color: aqua;" mode="aspectFill"></image>
								</view>
								<view class="flex flex-col flex-3">
									<text class="text-36r font-600">{{item.publisher.nickname}}</text>
									<text class="text-20r">{{vk.pubfn.dateDiff(item._add_time)}}</text>
								</view>
								<!-- 头像结束 -->

								<!-- 浏览 转发量 -->
								<view class="flex flex-1 items-center justify-around">
									<view class="flex items-center">
										<text class="mr-10r text-40r iconfont icon-fire" style="color: red;"></text>
										<text class="text-main">{{item.view_count}}</text>
									</view>
									<!-- 									<view class="flex items-center">
										<text class="text-50r iconfont icon-fenxiang1"></text>
										<text>10000</text>
									</view> -->
								</view>
								<!-- 浏览 转发量 结束 -->
							</view>
							<!-- 动态顶部 结束-->

							<!-- 内容部分 -->
							<view @click="itemClick(item,index)" class="pl-10r pr-10r">
								<text class="lines-2 truncate pt-10r mb-10r">{{item.content}}</text>
								<view v-if="item.dynamic_banner_imgs.length > 1" class="flex justify-around">
									<image class="w-360r h-360r rounded-15r mr-5r" :src="item.dynamic_banner_imgs[0]"
										mode="aspectFill">
									</image>
									<image class="w-360r h-360r rounded-15r ml-5r" :src="item.dynamic_banner_imgs[1]"
										mode="aspectFill">
									</image>
								</view>
								<view v-else class="flex justify-around">
									<image class="w-700r h-700r rounded-15r mr-5r" :src="item.dynamic_banner_imgs[0]"
										mode="aspectFill">
									</image>
								</view>
							</view>
							<!-- 内容部分 结束 -->

							<!-- 包含设计作品 -->
							<view v-if="item.hasWork" class="mt-20r flex items-center pl-5r pr-5r h-80r"
								style="border-top: 2rpx solid #E5E5E5 ;">
								<image class="w-60r h-60r" :src="item.relatedWork.cloth_imgs[0]" mode="aspectFill"></image>
								<text class="text-26r flex-1 ml-15r">{{item.relatedWork.template.name + '《' +item.relatedWork.name + '》'}}</text>
								<view class="text-light flex items-center text-30r">
									<text>相关设计</text>
									<text class="iconfont icon-youjiantou"></text>
								</view>
							</view>
							<!-- 包含设计 结束 -->
						</view>


					</scroll-view>


				</swiper-item>
				<swiper-item>
					<scroll-view refresher-enabled @refresherrefresh.stop="indexRefresh" :refresher-threshold="100" :refresher-triggered="trigger"
						scroll-y="true" style="height: 100%; background-color: #E5E5E5;">
						<view class="pl-20r pr-20r flex flex-wrap justify-between">
							<view v-for="(item,index) in data.dynamics" :key="index" @click="itemClick(item,index)" class="mt-10r mb-10r p-10r w-330r rounded-20r flex flex-col items-center"
								style="background-color: #fff;">
								<image class="w-330r h-330r rounded-20r " :src="item.dynamic_banner_imgs[0]" mode="aspectFill">
								</image>
								<view class="flex-1 lines-2 truncate self-start">{{item.content}}</view>
								<view class="self-start flex items-center justify-between" style="width: 100%;">
									<view class="flex items-center">
										<image :src="item.publisher.avatar" class=" mr-10r w-70r h-70r rounded-35r"
											mode="aspectFill"></image>
										<text class="text-30r">{{item.publisher.nickname.length>10 ? item.publisher.nickname.substr(0,10) + '...' : item.publisher.nickname}}</text>
									</view>
									<view class="">
										<text class="iconfont icon-dingwei"></text>
										<text class="text-25r">34米</text>
									</view>
								</view>

							</view>
						</view>



					</scroll-view>

				</swiper-item>
			</swiper>
		</view>

		<!-- 跳转弹窗 -->
		<view @click="popButtomClick" class="fixed z-10 pop-bottom" style="width: 100%;">
			<view class="w-80r h-80r text-center rounded-40r second-bg-color" style="margin: 0 auto;">
				<text class="leading-80r text-50r iconfont icon-jiahao" style="color: #fff;"></text>
			</view>
		</view>
		<!-- 跳转弹窗 -->

		<!-- 弹出层 -->
		<uni-popup @maskClick="popupMaskClick" ref="popup" type="bottom">
			<view class="h-200r flex justify-around main-bg-color" style="border-radius:50rpx 50rpx 0 0">
				<view @click="publishDynamic" class="text-deep text-center flex flex-col self-center">
					<view class="text-80r iconfont icon-fabu"></view>
					<view class="">发布动态</view>
				</view>
				<view @click="goDesign" class="text-deep text-center flex flex-col self-center">
					<view class="text-80r iconfont icon-sheji"></view>
					<view>设计衣服</view>
				</view>

			</view>
		</uni-popup>

		<!-- 弹出层 结束-->



	</view>
</template>


<script>
	var vk = uni.vk;
	export default {
		data() {
			// 页面数据变量
			return {
				// init请求返回的数据
				data: {

				},
				// 表单请求数据
				form1: {

				},
				scrollTop: 0,
				windowBottom: 0,
				navibarHeight: 0,
				curTabIndex: 1,
				trigger: false,
				fontColor: this.theme.mainColor,
				hasWork: true,
				enableRefresh:true,
				textContent: "这个真的可以冲！可以在冬天暖暖的羽绒服里,这个真的可以冲！可以在冬天暖暖的羽绒服里,这个真的可以冲！可以在冬天暖暖的羽绒服里"
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		// 监听 - 页面每次【加载时】执行(如：前进)
		onLoad(options = {}) {
			vk = uni.vk;
			this.options = options;
			this.init(options);
		},
		// 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快，会在页面进入动画完成前触发
		onReady() {

		},
		// 监听 - 页面每次【显示时】执行(如：前进和返回) (页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面)
		onShow() {

		},
		// 监听 - 页面每次【隐藏时】执行(如：返回)
		onHide() {

		},
		// 监听 - 点击右上角转发时
		onShareAppMessage(options) {

		},
		// 函数
		methods: {
			// 页面数据初始化函数
			init(options) {
				// vk.reLaunch("/pages_template/uni-id/index/index");
				// #ifdef MP
				uni.getSystemInfo({
					success: (r) => {
						let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
						let statusBarHeight = r.statusBarHeight;
						this.navibarHeight = menuButtonInfo.height;
					}
				})
				// #endif
				this.indexRefresh();


			},
			goHomePage(item, index) {
				vk.navigateTo({
					url: '/pages/homepage/homepage?id=' + item.publisher._id
				})
			},
			pageTo(path) {
				vk.navigateTo(path);
			},
			// 点击tab导航
			clikeTabNav(e) {
				let newIndex = parseInt(e);
				if (newIndex === this.curTabIndex) {
					return;
				}
				this.curTabIndex = newIndex;
			},
			swiperChange(e) {
				// console.log(e);
				this.curTabIndex = e.detail.current;

			},
			itemClick(item, index) {
				vk.navigateTo({
					url: '/pages/dynamic-detail/dynamic-detail?id=' + item._id
				})
			},
			goSearch() {
				uni.navigateTo({
					url: "/pages/search/search"
				})
				// this.pageTo("/pages/search/search");
			},
			indexRefresh() {
				console.log('refresh!');
				this.trigger = true;
				vk.callFunction({
					url: 'client/index/pub/getIndexData',
					title: '加载中...'
				}).then((r) => {
					this.data = r.data;
					console.log('首页数据是：' + this.data.dynamics[0]._id);
					this.trigger = false;
				});
			},
			popButtomClick() {
				uni.hideTabBar({
					animation: true,
					success: r => {
						this.$refs.popup.open();
					}
				})

			},
			popupMaskClick() {
				uni.showTabBar({
					animation: true,
					success: r => {}
				})
			},
			closePopup() {
				uni.showTabBar({
					animation: true,
					success: r => {
						this.$refs.popup.close();
					}
				})
			},
			publishDynamic() {
				this.closePopup();
				vk.navigateTo({
					url: '/pages/publish-dynamic/publish-dynamic',
					success: r => {
						this.closePopup();
					}
				})

			},
			goDesign() {
				this.closePopup();
				vk.navigateTo({
					url: '/pages/design/design',
					success: r => {
						this.closePopup();
					}
				})
			}
		},
		// 监听器
		watch: {

		},
		// 计算属性
		computed: {

		}
	}
</script>
<style lang="scss" scoped>
	.pop-bottom {
		bottom: calc(var(--window-bottom) + 10rpx);
	}

	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}
</style>
